﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace TimKiemDichVu
{
    public partial class ChooseServicePage : PhoneApplicationPage
    {
        public ChooseServicePage()
        {
            InitializeComponent();
        }

        private void CheckAll(bool bValue)
        {
            ckbAll.IsChecked = bValue;
            ckbATM.IsChecked = bValue;
            ckbBenXe.IsChecked = bValue;
            ckbBenXeBuyt.IsChecked = bValue;
            ckbBenhVien.IsChecked = bValue;
            ckbCongVien.IsChecked = bValue;
            ckbCoQuan.IsChecked = bValue;
            ckbCuaHangKiemKhiDienMay.IsChecked = bValue;
            ckbCho.IsChecked = bValue;
            ckbKhachSan.IsChecked = bValue;
            ckbNhaHang.IsChecked = bValue;
            ckbNhaTro.IsChecked = bValue;
            ckbPhongKham.IsChecked = bValue;
            ckbQuanAn.IsChecked = bValue;
            ckbQuanCafe.IsChecked = bValue;
            ckbQuanKaraoke.IsChecked = bValue;
            ckbRapChieuPhim.IsChecked = bValue;
            ckbSanBongDa.IsChecked = bValue;
            ckbSanVanDong.IsChecked = bValue;
            ckbShopDoGo.IsChecked = bValue;
            ckbShopThoiTrang.IsChecked = bValue;
            ckbSieuThi.IsChecked = bValue;
            ckbTiemHotToc.IsChecked = bValue;
            ckbTramXang.IsChecked = bValue;
            ckbTruongHoc.IsChecked = bValue;
        }

        private List<int> GetServiceList()
        {
            List<int> serviceList = new List<int>();

            #region
            if (ckbBenhVien.IsChecked.Value)
                serviceList.Add(1);

            if (ckbTruongHoc.IsChecked.Value)
                serviceList.Add(2);

            if (ckbQuanCafe.IsChecked.Value)
                serviceList.Add(3);

            if (ckbQuanAn.IsChecked.Value)
                serviceList.Add(4);

            if (ckbATM.IsChecked.Value)
                serviceList.Add(5);

            if (ckbTramXang.IsChecked.Value)
                serviceList.Add(6);

            if (ckbShopThoiTrang.IsChecked.Value)
                serviceList.Add(7);

            if (ckbTiemHotToc.IsChecked.Value)
                serviceList.Add(8);

            if (ckbQuanKaraoke.IsChecked.Value)
                serviceList.Add(9);

            if (ckbNhaHang.IsChecked.Value)
                serviceList.Add(10);

            if (ckbKhachSan.IsChecked.Value)
                serviceList.Add(11);

            if (ckbCongVien.IsChecked.Value)
                serviceList.Add(12);

            if (ckbCho.IsChecked.Value)
                serviceList.Add(13);

            if (ckbRapChieuPhim.IsChecked.Value)
                serviceList.Add(14);

            if (ckbSanBongDa.IsChecked.Value)
                serviceList.Add(15);

            if (ckbBenXe.IsChecked.Value)
                serviceList.Add(16);

            if (ckbPhongKham.IsChecked.Value)
                serviceList.Add(17);

            if (ckbBenXeBuyt.IsChecked.Value)
                serviceList.Add(18);

            if (ckbSanVanDong.IsChecked.Value)
                serviceList.Add(19);

            if (ckbNhaTro.IsChecked.Value)
                serviceList.Add(20);

            if (ckbSieuThi.IsChecked.Value)
                serviceList.Add(21);

            if (ckbCoQuan.IsChecked.Value)
                serviceList.Add(22);

            if (ckbCuaHangKiemKhiDienMay.IsChecked.Value)
                serviceList.Add(23);

            if (ckbShopDoGo.IsChecked.Value)
                serviceList.Add(24);
            #endregion

            if (serviceList.Count == (Application.Current as App).define.nServiceName)
            {
                serviceList.Clear();
                serviceList.Add(0);
            }

            return serviceList;
        }

        private void ckbAll_Click(object sender, RoutedEventArgs e)
        {
            if (ckbAll.IsChecked.Value)
            {
                CheckAll(true);
            }
            else
            {
                CheckAll(false);
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            (Application.Current as App).type = 2;
            if (GetServiceList().Count > 0)
            {
                (Application.Current as App).service.IndexList.Clear();
                (Application.Current as App).service.IndexList = GetServiceList();                
            }
            else
            {
            }
            NavigationService.GoBack();
        }
    }
}
